import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'

interface AttrProps {
    userId: number
    groupId: number
    name: string
    inputType: number
    value: string
    state?: number
    [key: string]: any
}

@Entity()
export class Attr {
    @PrimaryGeneratedColumn()
        id?: number

    @Column()
        userId!: number

    @Column()
        groupId!: number

    @Column()
        name!: string

    @Column()
        inputType!: number

    @Column({ length: 2000 })
        value!: string
    @Column({ default: 1 })
        state?: number

    @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
        createTime?: number

    constructor(props: AttrProps | undefined) {
        if (!props) return
        this.userId = props.userId
        this.groupId = props.groupId
        this.name = props.name || props.AttrName
        this.inputType = props.inputType
        this.value = props.value
        this.state = props.state
    }
}